<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>创建合同订单</title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
    <script src="${ctxStatic}/js/DateTimePicker.js"></script>
    <script src="${ctxStatic}/js/layer.js"></script>
    <script src="${ctxStatic}/js/style.js"></script>
    <script src="${ctxStatic}/dateCalendar/WdatePicker.js"></script>
    <link rel="stylesheet" href="${ctxStatic}/css/common.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    <script type="text/javascript">
    $(document).ready(function(){
    	var form = $("#inputForm");  
        form.validate();//验证指定的表单
    	$("#financeCurrency").select2();
    	$("#itemID").select2();
    	$("#ognizationId").select2();
    	setFinanceAmountName();
   		$("#okButton").click(function(){
    		if (form.valid()) {//如果表单验证成功，则进行提交。  
	    		$.post("${ctx}/init/finance/checkExsit?ognizationId="+$("#ognizationId").val(),"",function(result){
	    			if (result == "false") {
	    				tipParent("该组织初始数据已存在");
	    			}else{
			    		$("#showHtml").addClass("showHtml");
			            $("select").attr('disabled','disabled')
			            $("#okHead").show();
			            $("#createHead").hide();  
	    			}
		            return false;
	    		},'json');
          	}
     	});
    });
    
    /* 保存创建/编辑信息 */
    function saveForm(){
        $("select").attr('disabled',false);
    	formUnFormat($("#inputForm"));
    	var params = $("#inputForm").serialize();
    	$.post("${ctx}/init/finance/save",params,function(result){
    		/* 弹出提示框,刷新父页面,关闭当前页面 */
    		tipParent(result.message);
    		window.parent.frames[0].searchListForm();
    		closeWin();
    	},'json');
    	
    }
    /**
     *机构联动
     */
    function ognizationFun() {
    	var ognizationId=$("#ognizationId").find("option:selected").val();
    	var ognizationType=$("#ognizationId").find("option:selected").attr("data-value");
    	$("#itemID").find("option").attr("selected",false);
    	$("#s2id_itemID").remove();
    	if (ognizationType=="5") {
			//$("#itemID").find("option:contains('<spring:message code="init_finance_create_initialReceivables"/>')").attr("selected",true);
			$("#itemID").val("IF_10");
    	}else if(ognizationType=="3"||ognizationType=="4"){
			//$("#itemID").find("option:contains('<spring:message code="init_finance_create_initialPayment"/>')").attr("selected",true);
    		$("#itemID").val("IF_20");
		}
		$("#itemID").select2();
		setFinanceAmountName();
    	var param={"ognizationId":ognizationId};
    	$.post("${ctx}/init/finance/ognizatianFun",param,function(result){            
        	$("#addressHtml").html($(callBackHtml(result)).find("#addressHtml").html());
        	$("#contactHtml").html($(callBackHtml(result)).find("#contactHtml").html());
        },'html');
	}
    
  	/**
    *设置款项金额name属性
    */
    function setFinanceAmountName(){
  		//选择期初应收款
    	if ($("#itemID").val() == "IF_10") {
			$("#financeAmount").attr("name","realCreditAmount");
			$("#nullAmount").attr("name","realDebitAmount");
		//选择期初应付款
		}else if($("#itemID").val() == "IF_20"){
			$("#financeAmount").attr("name","realDebitAmount");
			$("#nullAmount").attr("name","realCreditAmount");
		}
    }
    </script>
    <style type="text/css">
    .linkBox{
	color:#0a6dca;
	cursor:pointer;
	text-decoration:underline;
	}
	.showHtml input{
	border:none;
	background-color:inherit;
	color:#333;
	}
    </style>
</head>
<form id="inputForm">
<body>   

<div id="createHead" class="layerHeader clearfix">
<c:choose>
	   <c:when test="${settlementEntity.id!=null && settlementEntity.id!=0}">
	    <!-- 编辑 --> 
			<p class="headerTitle"><spring:message code="init_finance_create_editInitFinance" /></p>
       </c:when>
       <c:otherwise>
        <!-- 创建 --> 
            <p class="headerTitle"><spring:message code="init_finance_create_createInitFinance" /></p>
       </c:otherwise>
    </c:choose>
	
    <div class="headerButton clearfix">
        <!-- 确定 -->
        <button type="button" id="okButton"><spring:message code="purchaseAdvance_edit_ok"/></button>
        <!-- 取消 -->
        <button type="button" onclick="closeWin()"><spring:message code="purchaseAdvance_edit_cancle"/></button>
    </div>
</div>
<!-- 确认画面头部 -->
<div id="okHead" class="layerHeader clearfix" style="display: none;">	      
             <p class="headerTitle"><spring:message code="init_finance_create_okInitFinance" /></p>    
    <div class="headerButton clearfix">
	    <!-- 编辑 保存 --> 
			<button type="button" onclick="saveForm();"><spring:message code="common_save" /></button>
        <!-- 取消 -->
          <button type="button" onclick="closeWin()"><spring:message code="purchaseAdvance_edit_cancle"/></button>
    </div>
</div>

<div id="showHtml" class="smOrderBox">
		<c:set value="<%=ResourcesUtil.getConfig(\"financeCategory07\") %>" var="financeCategory07"/>
        <input type="hidden" id="id" name="id" value="${settlementEntity.id }">
        <input type="hidden" id="financePeriod" name="financePeriod" value="${fns:getDate('yyyy-MM') }"/>
        <input type="hidden" id="financeCategory" name="financeCategory" value="${financeCategory07 }"/>
        <div class=" clearfix" >
        	<p class="title" style="margin-top: 2px"><spring:message code="init_finance_create_ognizationInfo" /></p>
        </div>
    <div class="items clearfix">
        <div class="col-50 clearfix haveToBox">
        <!-- 机构名 -->
            <p class="tit" style="width: 80px"><spring:message code="init_finance_create_ognizationName" /></p>
            <select  name="ognizationId" id="ognizationId" style="width: 300px" onchange="ognizationFun();" data-rule-required="true" data-msg-required="<spring:message code="init_finance_error_msg_ognizationID"/>">
                   <option value=""><spring:message code="order_please_choose"/></option>
                   <c:forEach items="${ognizationList}" var="ognization">
                       <option data-value="${ognization.ognizationType}" value="${ognization.id}" <c:if test="${financeEntity.ognization.id eq ognization.id }">selected="selected"</c:if>>${ognization.ognizationName}</option>
                   </c:forEach>
            </select>
            <p class="haveTo">*</p>
        </div>
    </div>
    <div id="addressHtml" class="items clearfix showHtml">
        <div class="clearfix">
        <!-- 组织机构地址  -->
            <p class="tit" style="width: 80px"><spring:message code="init_finance_create_ognizationAddress" /></p>
             <input type="text" style="width: 500px;" value="${financeEntity.ognization.ognizationAddress }" disabled="disabled">
        </div>
    </div>
    <div id="contactHtml" class="items clearfix showHtml" >        	
                <div class="col-50 clearfix">
                <!-- 主联系人 -->
                    <p class="tit" style="width: 80px"><spring:message code="init_finance_create_contactUser" /></p>
                    <input type="text" value="${financeEntity.ognization.contactPerson }" disabled="disabled">
                </div>
                
                <div class="col-50 clearfix">
                <!-- 联系电话 -->
                    <p class="tit" style="width: 80px"><spring:message code="init_finance_create_contactPhone" /></p>
                    <input type="text" value="${financeEntity.ognization.contactPhone }" disabled="disabled">
                </div>
            </div>
    <div class=" clearfix" >
        	<p class="title" style="margin-top: 2px"><spring:message code="init_finance_create_itemInfo" /></p>
        </div>
            <div id="itemHtml" class="items clearfix" >        	
                <div class="col-50 clearfix haveToBox">
                <!-- 款项类别 -->
                <c:set value="<%=ResourcesUtil.getConfig(\"init_finance\") %>" var="initFinance"/>
                    <p class="tit" style="width: 80px"><spring:message code="init_finance_create_itemName" /></p>
                    <select id="itemID" style="width: 150px" onchange="setFinanceAmountName();" data-rule-required="true" data-msg-required="<spring:message code="init_finance_error_msg_financeCategory"/>">
                   		<option value=""><spring:message code="order_please_choose"/></option>
                   		<c:forEach items="${fns:getDictList(initFinance)}" var="item">
                       		<option value="${item.itemValue}"
                       		<c:choose>
			                    <c:when test="${settlementEntity.realDebitAmount != null && item.itemValue == 'IF_10'}">
		                    		selected="selected"
			                    </c:when>
			                    <c:when test="${settlementEntity.realCreditAmount != null && item.itemValue == 'IF_20'}">
		                    		selected="selected"
			                    </c:when>
		                    </c:choose>
                       		>${item.itemNameCn}</option>
                   		</c:forEach>
            		</select>
                    <p class="haveTo">*</p>
                </div>
                
                <div class="col-50 clearfix haveToBox">
                <c:set value="QUOTATION_CURRENCY" var="quotationCurrency"/>
                <!-- 结算货币 -->
                    <p class="tit" style="width: 80px"><spring:message code="init_finance_create_financeCurrency" /></p>
                    <select  name="financeCurrency" id="financeCurrency" style="width: 150px" data-rule-required="true" data-msg-required="<spring:message code="init_finance_error_msg_financeCurrency"/>">
                   		<option value=""><spring:message code="order_please_choose"/></option>
                   		<c:forEach items="${fns:getDictList(quotationCurrency)}" var="currency">
                       		<option value="${currency.itemCode}-${currency.itemValue}" 
                       		<c:if test="${fn:split(financeEntity.financeCurrency,'-')[1] eq currency.itemValue }">selected="selected"</c:if>
                       		>${currency.itemNameCn}</option>
                   		</c:forEach>
            		</select>
                    <p class="haveTo">*</p>
                </div>
            </div>
            <div class="items clearfix haveToBox">        	
                <div class="col-50 clearfix">
                <!-- 款项金额  -->
                    <p class="tit" style="width: 80px"><spring:message code="init_finance_create_financeAmount" /></p>
                    <input type="tel" id="financeAmount" value="<fmt:formatNumber value="${settlementEntity.realDebitAmount}${settlementEntity.realCreditAmount}" pattern="#,##0.00###"/>" onblur="formatMoney(this,2);" onfocus="unFormat(this);" data-rule-required="true" data-msg-required="<spring:message code="init_finance_error_msg_financeAmount"/>">
           			<input type="hidden" id="nullAmount" value=""/>
           			<p class="haveTo">*</p>
                </div>
            </div>
            <div class="items clearfix showHtml">
                
        		<div class="clearfix">
        		<!-- 备注 -->
            		<p class="tit" style="width: 80px"><spring:message code="init_finance_create_remarks" /></p>
            		<textarea name="remarks" style="width:630px;height: 60px">${settlementEntity.remarks }</textarea>
        		</div>
    	</div>
    	<div class="items clearfix showHtml">        	
                <div class="col-50 clearfix">
                <!-- 创建人员  -->
                    <p class="tit" style="width: 80px"><spring:message code="init_finance_create_creator" /></p>
                    <input type="text" value="${settlementEntity.createBy.firstName }${settlementEntity.createBy.lastName }" disabled="disabled">
                </div>
                <div class="col-50 clearfix">
                <!-- 创建时间  -->
                    <p class="tit" style="width: 80px"><spring:message code="init_finance_create_createDate" /></p>
                    <c:choose>
                    	<c:when test="${financeEntity.id!=null&&financeEntity.id!=0}">
                    		<input type="text" value='<fmt:formatDate value="${settlementEntity.createDate }" pattern="yyyy-MM-dd"/>' disabled="disabled">
                    	</c:when>
                    	<c:otherwise>
                    		<input type="text" value="${fns:getDate('yyyy-MM-dd') }" disabled="disabled">
                    	</c:otherwise>
                    </c:choose>
                </div>
            </div>
</div>
</form>
<script>
	window.onload = function(){
	$('.tableScrollSm').css('height','325px')
	$('td input').each(function(){
		var tdH = $(this).parents('td').height()
		$(this).css('height',tdH)
		})
	}
	var tableW = $('.tableHead').outerWidth();
	$('.tableScroll').css('width',tableW + 18 + 'px')

</script>
</body>
</html>
